package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Roleprocess;
import com.restaurant.service.RoleprocessService;

public class RoleprocessServiceImpl implements RoleprocessService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Roleprocess addOrModify( Roleprocess objRoleprocess ) {
       return ( Roleprocess ) hibernateTemplate.merge( objRoleprocess );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Roleprocess deleteRecord( Roleprocess objRoleprocess ) {
       hibernateTemplate.delete( objRoleprocess );
       return objRoleprocess;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Roleprocess modifyRecord( Roleprocess objRoleprocess ) {
       return ( Roleprocess ) hibernateTemplate.merge( objRoleprocess );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Roleprocess> loadAll() {
       return (List<Roleprocess>)hibernateTemplate.findByNamedQuery( "Roleprocess.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Roleprocess loadByPrimaryKey( Long primaryKey ) {
       return (Roleprocess) hibernateTemplate.get( Roleprocess.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Roleprocess deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Roleprocess> loadByHql(String query) {
       return ( List<Roleprocess> ) hibernateTemplate.find( query );
   }
}